﻿@Imports SchoolClick.Database.jqGrid
@Code
    Dim grid = New JqGridHelper(Of MATERIA)("table-materias",
       dataType:=JqGridDataTypes.Json, methodType:=JqGridMethodTypes.Post, pager:=True,
       rowsNumber:=20,
       viewRecords:=True,
       rowsNumbers:=True,
       width:=920, height:=400, multiSelect:=True
    ).Navigator(New JqGridNavigatorOptions() With {.Add = True, .Edit = False, .Delete = True, .Search = False,
                                                  .AddFunction = "$.handlerFakejqGrid", .AddText = "Nueva materia",
                                                  .DeleteToolTip = "Eliminar la(s) materia(s) seleccionada(s)",
                                                  .DeleteText = "Eliminar",
                                                  .AddToolTip = "Crear y asociar una nueva materia al grado actual"}
    )
End Code
@Html.TableFields("Grados disponibles para el nuevo año escolar"
    ).AddField("cmbGrados", "Seleccione el grado para ver las materias que se impartirán", JFControlType.ComboBox, New JFOptionsFields().setSource(Url.Action("_getGrados_AJAX", "AnioEscolar"))
).SetTableWidth(920
).AddJavaScript(String.Format("$('#jerti-content').attr('data-year-ae', '{0}');", ViewBag.Year)
).AddJavaScript(grid.GetJavaScript.ToHtmlString
).AddJavaScript("$('#cmbGrados').on({change: function () {$('#table-materias').jqGrid('setGridParam', { url: '/AnioEscolar/_get_materias_newae?Grado=' + this.value + '&Year=' + $('#jerti-content').attr('data-year-ae')}).trigger('reloadGrid').jqGrid('setGridParam', {editurl:'/AnioEscolar/_delete_materia_grado?Grado=' + this.value + '&Year=' + $('#jerti-content').attr('data-year-ae')}); $('#add_table-materias').attr('href', '/Matricula/AnioEscolar/_get_MateriasNotAssociated?Year=' + $('#jerti-content').attr('data-year-ae') + '&Grado=' + this.value);},loadSuccess: function () {$('#table-materias').jqGrid('setGridParam', { url: '/AnioEscolar/_get_materias_newae?Grado=' + this.value + '&Year=' + $('#jerti-content').attr('data-year-ae') }).trigger('reloadGrid').jqGrid('setGridParam', {editurl:'/AnioEscolar/_delete_materia_grado?Grado=' + this.value + '&Year=' + $('#jerti-content').attr('data-year-ae')}); $('#add_table-materias').attr('href', '/Matricula/AnioEscolar/_get_MateriasNotAssociated?Year=' + $('#jerti-content').attr('data-year-ae') + '&Grado=' + this.value);}});"
).AddJavaScript("$('#add_table-materias').on({"
).AddJavaScript("open: function () {$('#table-materias-no-asociadas').jqGrid('setGridParam', { url: '/AnioEscolar/_get_materias_not_included_grado?Grado=' + $('#cmbGrados').val() + '&Year=' + $('#jerti-content').attr('data-year-ae') }).trigger('reloadGrid');},"
).AddJavaScript("setParametros: function () {return 'grado='+ $('#cmbGrados').val() + '&id=' + $('#table-materias-no-asociadas').jqGrid('getGridParam', 'selarrrow');},"
).AddJavaScript("saveSuccess: function () {$('#table-materias').trigger('reloadGrid');}});")

@grid.GetHtml()
@Html.loadDialogPartialViewAJAX("#add_table-materias", "add-materia", "ASOCIAR MATERIA(S) AL GRADO")
<br />
<br />

<script type="text/javascript">
    //$(function() {
    //    $('#add_table-materias').on({
    //            open: function () {$("#table-materias-no-asociadas").jqGrid('setGridParam', { url: '/AnioEscolar/_get_materias_not_included_grado?Grado=' + $('#cmbGrados').val() + '&Year=' + $('#jerti-content').attr('data-year-ae') }).trigger("reloadGrid");},
    //            setParametros: function () {return 'grado='+ $('#cmbGrados').val() + '&id=' + $("#table-materias-no-asociadas").jqGrid('getGridParam', 'selarrrow');},
    //            saveSuccess: function () {$("#table-materias").trigger("reloadGrid");}
    //        });
    //})
</script>